package cuckoo.ioc.container;

import java.util.Set;

import cuckoo.ioc.factory.BeanFactory;
import cuckoo.ioc.factory.DefaultBeanFactory;

public abstract class BeanFactoryContainer implements BeanContainer {

	protected BeanFactory beanFactory = new DefaultBeanFactory();

	@Override
	public <T> T getBean(Class<T> clazz) {
		return beanFactory.getBean(clazz);
	}

	public void setBeanFactory(BeanFactory beanFactory) {
		this.beanFactory = beanFactory;
	}

	public void register(Class<?>... classes) {
		beanFactory.register(classes);
	}

	public void registerIndependent(String name, Object obj) {
		beanFactory.registerIndependent(name, obj);
	}

	@Override
	public <T> T getBean(String name, Class<T> clazz) {
		return beanFactory.getBean(name, clazz);
	}

	protected void destroy() {
		if (beanFactory != null)
			beanFactory.destory();
	}

	@Override
	public Set<String> getAllBean() {
		return beanFactory.getAllBean();
	}

	@Override
	public Object getBean(String name) {
		return beanFactory.getBean(name);
	}
}
